(function ($) {
    // 手机验证接口
    var vkey = '';
    var url = "http://mobile-mapi.78diy.com:81/emvip.php?s=Home/Index/check";
    //console.log(url);
    $('#fsyzm').bind('click', function () {
        var tel = $('#tel').val();

        $.ajax({
            type: "GET",
            url: url,
            data: "tel=" + tel,
            datatype: 'json',
            success: function (msg) {
                var msg = eval("(" + msg + ")");
                //console.log(msg);
                if (msg.return_code == 0) {
                    vkey = msg.data.key;
                    $('#message_code').val(vkey);
                    alert('验证码发送成功!');
                } else {
                    alert('验证码发送失败!');
                }
            }
        });
        return false;
    });

    // form提交接口
    $('.tj').on('click', function () {
        var url = "http://mobile-mapi.78diy.com:81/emvip.php?s=Home/Index/submit";

        var id = $('#id');
        var nickname = $('#nickname');
        var vip_level = $('#vip_level');
        var name = $('#name');
        var birth = $('#birth');
        var qq = $('#qq');
        var occupation = $('#occupation');
        var tel = $('#tel');
        var send_num = $('#send_num');
        var address = $('#address');
        var message_code = $('#message_code');

        var id_val = id.val();
        var nickname_val = nickname.val();
        var vip_level_val = vip_level.val();
        var name_val = name.val();
        var birth_val = birth.val();
        var qq_val = qq.val();
        var occupation_val = occupation.val();
        var tel_val = tel.val();
        var send_num_val = send_num.val();
        var address_val = address.val();
        var message_code_val = message_code.val();

        if (id_val === '') {
            id.focus();
            alert('请填写游戏角色数字ID!');
            return false;
        } else if (nickname_val === '') {
            nickname.focus();
            alert('请填写游戏角色昵称!');
            return false;
        } else if (vip_level_val === '') {
            vip_level.focus();
            alert('请填写游戏VIP等级!');
            return false;
        } else if (name_val === '') {
            name.focus();
            alert('请填写姓名!');
            return false;
        } else if (qq_val === '') {
            qq.focus();
            alert('请填写QQ!');
            return false;
        } else if (tel_val === '') {
            tel.focus();
            alert('请填写手机号码!');
            return false;
        } else if (send_num_val === '') {
            send_num.focus();
            alert('请填写验证码!');
            return false;
        } else if (address_val === '') {
            address.focus();
            alert('请填写详细地址!');
            return false;
        } else {
            $.ajax({
                type: "post",
                url: url,
                data: 'id_val=' + id_val + '&nickname_val=' + nickname_val + '&vip_level_val=' + vip_level_val + '&name_val=' + name_val + '&birth_val=' + birth_val + '&qq_val=' + qq_val + '&occupation_val=' + occupation_val + '&tel_val=' + tel_val + '&send_num_val=' + send_num_val + '&address_val=' + address_val + '&message_code_val=' + message_code_val,
                success: function (msg) {
                    var msg = eval("(" + msg + ")");
                    //console.log(msg);
                    if (msg.return_code == 0) {
                        alert('提交成功!');                        
                        window.location.href = 'http://www.emkxq.com/index.html';
                    } else if(msg.return_code == 2){
                        alert('该游戏ID已提交，请勿重复提交!');
                    }else {
                        alert('提交失败!');
                    }
                    //alert(msg);
                }
            });
        }
        return false;
    });
})(jQuery);